home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 41
/
Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso
/
Aminet
/
comm
/
tcp
/
rxsocket.lha
/
rxsocket
/
examples
/
revserv.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
2000-11-28
|
2KB
|
80 lines
/*
A simple stand alone service example.
It waits for connections on port 4000.
After a connection is made,
it waits for a string of max 256 char len and send it back reversed.
To run it:
- be sure TCP port 4000 is free (e.g. you don't have pserv.rexx
enabled in inetd database, if you installed it).
Open a shell and write:
- rx revserv.
To stop it:
- CTRL_C in the shell where rvserv is running
or
- rx "shell 'REVSERVPORT' 'QUIT'"
*/
l="rexxsupport.library";if ~show("L",l) then;if ~addlib(l,0,-30) then do;say "can't find" l;exit;end
l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then do;say "can't find" l;exit;end
l="rxsocket.library";if ~show("L",l) then;if ~addlib(l,0,-30) then do;say "can't find" l;exit;end
prg = ProgramName("NOEXT")
if ~Open("STDERR","*","W") | ~OpenPort("REVSERVPORT") then exit
sock = socket("INET","STREAM","IP")
if sock<0 then call err "can't create socket:" errno()
local.ADDRFAMILY = "INET"
local.ADDRADDR = 0
local.ADDRPORT = 4000
if bind(sock,"LOCAL")<0 then call err "can't bind port 4000:" errno()
sig = PortSignal("REVSERVPORT")
SEL.READ.0=sock
open = 1
do while open
if Listen(sock,5)<0 then call err "listen error:" errno()
res = WaitSelect("SEL",,,sig)
pkt = GetPkt("REVSERVPORT")
if pkt ~= null() then do
comm= GetArg(pkt)
call reply(pkt)
if upper(comm) == "QUIT" then open = 0
end
if sel.0.read then do
lsock = accept(sock,"REMOTE")
if lsock<0 then call err "accept() error:" errno()
auth = AuthFun(remote.addrAddr,4000,remote.addrPort)
say auth
len = recv(lsock,"BUF",256)
if len>0 then do
buf = reverse(buf)
if send(lsock,buf) ~= length(buf) then call err "send() error:" errno()
end
if ( len < 0 ) & ( errno() ~= 35 )
then call err "recv() error:" errno()
call CloseSocket(lsock)
end
end
exit
err: procedure expose prg
parse arg msg
say prg":" msg
exit